<?php

namespace App\Jobs;

use App\Wen\Utils\Settings;
use App\Wen\Utils\StatisticUtils;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;

class CalculateFollowsNumJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    protected $user_id =  0;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($user_id)
    {
        //
        $this->user_id = $user_id;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        global $__MINI_GLOBAL_PAYCODE_9__;
        if(!$__MINI_GLOBAL_PAYCODE_9__){
            return;
        }
        if(_empty_($this->user_id)){
            return;
        }
        //
        $follow_rate = _between_(Settings::get('robot_action_follow_rate', 100), 0, 100) / 100;
        if($follow_rate == 0){
            return;
        }
        $author_fans = StatisticUtils::user_fans_count($this->user_id);
        $author_be_likes = StatisticUtils::user_beliked_count($this->user_id);
        $author_post_count = StatisticUtils::user_post_count($this->user_id);
        $author_be_collected = StatisticUtils::user_becollected_count($this->user_id);
        $I = 0.1 * log($author_fans + 1) + 0.2 * log($author_be_likes + 1) + 0.3 * $author_post_count + 0.4 * $author_be_collected;

        $new_fans = (int)($I * 10 * $follow_rate);
        if($new_fans){
            ImitateUserFollowsStepJob::dispatch($this->user_id, $new_fans)->delay(now()->addMinutes(mini_rand(6, 30)));
        }
    }
}
